//package com.zhs.study.task;
//
//import jdk.internal.org.xml.sax.ErrorHandler;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
//import org.springframework.scheduling.support.ScheduledMethodRunnable;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Nullable;
//import java.util.IdentityHashMap;
//import java.util.Map;
//import java.util.concurrent.ScheduledFuture;
//
///**
// * @author zhenghuisheng
// * @date : 2023/5/23
// */
//
//@Component
//public class CustomTaskScheduler extends ThreadPoolTaskScheduler {
//    private static final long serialVersionUID = 1L;
//
//    private final Map<Object, ScheduledFuture<?>> scheduledTasks = new IdentityHashMap<>();
//
//    @Nullable
//    private volatile ErrorHandler errorHandler;
//
//    /**
//     * <p>Title: cancelTask</p>
//     * <p>Description: 取消定时器执行</p>
//     * @param identifier scheduledTasks.put 的值
//     * @author hfuquan
//     * @Date 2020年9月11日 上午11:37:06
//     */
//    void cancelTask(Object identifier) {
//        ScheduledFuture<?> future = scheduledTasks.get(identifier);
//        if (null != future) {
//            future.cancel(true);
//        }
//    }
//
//    /**
//     * 使用 @Scheduled(fixedRate = xxL) 时，项目启动时，会自动调用这个方法，
//     * 一个类同时有多个@Scheduled，所产生的
//     * call parent method and store the result Future for cancel task,
//     * you can expand other method of you used.
//     *
//     * @param task   the task need to be executed
//     * @param period the time between two continues execute
//     * @return the result of task
//     */
//    @Override
//    public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
//        ScheduledFuture<?> future = super.scheduleAtFixedRate(task, period);
//        ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task;
////        scheduledTasks.put(ProcessorTask.CANCEL_TASK_METHOD_NAME, future);
//        scheduledTasks.put(runnable.getTarget(), future);
//        return future;
//    }
//
//}
